﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Kojarskiy.Core;
using Kojarskiy.Models;

namespace Kojarskiy.Controllers
{
    [Authorize(Roles = "Administrators")]
    public class AdminController : Controller
    {
        protected KojarskiyDbEntities context = new KojarskiyDbEntities();
        //
        // GET: /Admin/

        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Log()
        {
            return View();
        }
        public ActionResult SmtpSettings()
        {

            return View(SettingsManager.SmtpSettings);
        }

        [HttpPost]
        public ActionResult SmtpSettings(SmtpSettings settings)
        {

            if (SettingsManager.SaveSmtpSettings(context, settings))
            {
                KojarskiyApplication.Message = new Message(MessageType.Success, "Настройки подключения к SMTP серверу сохранены!");
            }
            else KojarskiyApplication.Message = new Message(MessageType.Error, "Ошибка сохранения SMTP настроек!");

            return View(SettingsManager.SmtpSettings);
        }
    }
}
